﻿using System;
using System.Data;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using MxWeiXinPF.Common;
using MxWeiXinPF.BLL;

namespace MxWeiXinPF.Web.admin.jiaoshuifei
{
    public partial class baoxiu_edit : Web.UI.ManagePage
    {
        //1e2124dd04e11d01b9df2865f85944be
        private string action = MXEnums.ActionEnum.Edit.ToString(); //操作类型

        shuifei_baoxiu baoxiuBll = new shuifei_baoxiu();

        protected void Page_Load(object sender, EventArgs e)
        {

            ChkAdminLevel("baoxiu", MXEnums.ActionEnum.View.ToString()); //检查权限

            string _action = MXRequest.GetQueryString("action");
            int id = 0;

            this.action = MXEnums.ActionEnum.Edit.ToString();//修改类型
            if (!int.TryParse(Request.QueryString["id"] as string, out id))
            {
                JscriptMsg("传输参数不正确！", "back");
                return;
            }
            if (!baoxiuBll.Exists(id))
            {
                JscriptMsg("记录不存在或已被删除！", "back");
                return;
            }

            if (!Page.IsPostBack)
            {
                ShowInfo(id);

            }
        }

         

        #region 赋值操作=================================
        //1e2124dd04e11d01b9df2865f85944be
        private void ShowInfo(int id)
        {
            hidid.Value = id.ToString();
            Model.shuifei_baoxiu baoxiuModel = baoxiuBll.GetModel(id);
            Model.wx_userweixin weixin = GetWeiXinCode();
            if (weixin.id != baoxiuModel.wid)
            {
                JscriptMsg("非法请求！", "back");
                return;
            }

            lblbx_type.Text = baoxiuModel.bx_type.ToString();
            lblcreate_time.Text =MyCommFun.Obj2DateTime( baoxiuModel.create_time).ToString();
            lblcontact_person.Text = MyCommFun.ObjToStr( baoxiuModel.contact_person);
            lblcontact_tel.Text = MyCommFun.ObjToStr(baoxiuModel.contact_tel);
            lbladdr.Text = MyCommFun.ObjToStr(baoxiuModel.addr);
            lblbx_content.Text = MyCommFun.ObjToStr(baoxiuModel.bx_content);
            if (baoxiuModel.bx_pic != null)
            {
                imgbx_pic.ImageUrl = baoxiuModel.bx_pic;

            }
            else
            {
                imgbx_pic.Visible = false;
            }

            if (baoxiuModel.has_repair && baoxiuModel.repair_time != null)
            {
                lblhas_repair.Text = "已处理";
                lblrepair_time.Text = baoxiuModel.repair_time.ToString();
            }
            else
            {
                lblhas_repair.Text = "未处理";
            }
        }

        #endregion



        //保存
        protected void btnSubmit_Click(object sender, EventArgs e)
        {

            ChkAdminLevel("baoxiu", MXEnums.ActionEnum.Edit.ToString()); //检查权限
               
            int id = MyCommFun.Str2Int(hidid.Value);
            Model.shuifei_baoxiu baoxiuModel = baoxiuBll.GetModel(id);
            Model.wx_userweixin weixin = GetWeiXinCode();
            if (weixin.id != baoxiuModel.wid)
            {
                JscriptMsg("非法请求！", "back");
                return;
            }
            baoxiuModel.has_repair = true;
            baoxiuModel.repair_time = DateTime.Now;
            //1修改主表
            baoxiuBll.Update(baoxiuModel);
            AddAdminLog(MXEnums.ActionEnum.Edit.ToString(), "处理保修信息成功，主键为" + id); //记录日志
            JscriptMsg("处理保修信息成功！", "baoxiu_list.aspx");


        }

    }
}